{{- if and .Values.global.modules.publicDomainTemplate .Values.global.clusterIsBootstrapped }}
---
kind: Deployment
apiVersion: apps/v1
metadata:
  name: documentation
  namespace: d8-system
  {{- include "helm_lib_module_labels" (list . (dict "app" "documentation")) | nindent 2 }}
spec:
  replicas: 1
  revisionHistoryLimit: 2
  selector:
    matchLabels:
      app: documentation
  template:
    metadata:
      labels:
        app: documentation
    spec:
      {{- include "helm_lib_node_selector" (tuple . "system") | nindent 6 }}
      {{- include "helm_lib_tolerations" (tuple . "system") | nindent 6 }}
      {{- include "helm_lib_priority_class" (tuple . "cluster-low") | nindent 6 }}
      {{- include "helm_lib_module_pod_security_context_run_as_user_root" . | nindent 6 }}
      imagePullSecrets:
      - name: deckhouse-registry
      serviceAccountName: documentation
      containers:
      - name: web
        image: {{ include "helm_lib_module_image" (list $ "web") }}
        ports:
          - containerPort: 8080
            name: http
            protocol: TCP
        lifecycle:
          preStop:
            exec:
              command: ["/opt/nginx-static/sbin/nginx", "-s", "quit"]
        resources:
          requests:
            {{- include "helm_lib_module_ephemeral_storage_logs_with_extra" 10 | nindent 12 }}
  {{- if not ( .Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
            {{- include "web_resources" . | nindent 12 }}
  {{- end }}
        securityContext:
          allowPrivilegeEscalation: false
        volumeMounts:
          - name: config
            mountPath: /app/config
          - name: nginx-config
            mountPath: /opt/nginx-static/conf/nginx.conf
            subPath: nginx.conf
          - name: tmp
            mountPath: /tmp
          - mountPath: /app/modules/en
            name: modules-docs-en
          - mountPath: /app/modules/ru
            name: modules-docs-ru
      - name: builder
        image: {{ include "helm_lib_module_image" (list $ "docsBuilder" "docs-builder") }}
        {{ include "helm_lib_module_container_security_context_not_allow_privilege_escalation" . | nindent 8 }}
        command:
          - "/app/server"
        env:
          - name: HUGO_ENVIRONMENT
            value: production
          - name: POD_IP
            valueFrom:
              fieldRef:
                fieldPath: status.podIP
          - name: POD_NAME
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.name
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.namespace
          - name: CLUSTER_DOMAIN
            value: {{ $.Values.global.discovery.clusterDomain | quote }}
        ports:
          - containerPort: 8081
            name: http
            protocol: TCP
        livenessProbe:
          httpGet:
            path: /healthz
            port: 8081
        readinessProbe:
          httpGet:
            path: /healthz
            port: 8081
        resources:
          requests:
            {{- include "helm_lib_module_ephemeral_storage_logs_with_extra" 10 | nindent 12 }}
  {{- if not ( .Values.global.enabledModules | has "vertical-pod-autoscaler-crd") }}
            {{- include "builder_resources" . | nindent 12 }}
  {{- end }}
        volumeMounts:
          - name: tmp
            mountPath: /tmp
          - mountPath: "/mount/public/en/modules"
            name: modules-docs-en
          - mountPath: "/mount/public/ru/modules"
            name: modules-docs-ru
      volumes:
        - name: config
          configMap:
            name: d8-deckhouse-version-info
        - name: nginx-config
          configMap:
            name: documentation-nginx-config
        - name: tmp
          emptyDir: {}
        - name: modules-docs-en
          emptyDir: {}
        - name: modules-docs-ru
          emptyDir: {}
{{- end }}
